#include "FullyAssociativeCache.h"

FullyAssociativeCache::FullyAssociativeCache(unsigned size, unsigned lineSize) :
	Cache(size, lineSize)
{
	lines = size/lineSize;
	cache = new int[lines];
	for(int i=0; i<lines; i++)
	cache[i] = -1;
}

FullyAssociativeCache::~FullyAssociativeCache()
{
	delete [] cache;
}

float FullyAssociativeCache::getFilled()
{
	int fullCounter = 0;
	for(int i = 0; i < lines; ++i)
		if(cache[i] != -1)
			fullCounter++;

	return (float)fullCounter / lines;
}

bool FullyAssociativeCache::checkHit()
{
	for(int i = 0; i < lines; ++i)
		if(cache[i] == currentTag)
			return true;

	cache[0] = currentTag;
	return false;
}



